<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>tableeditor.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_tableeditor.js.html">tableeditor.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Plugin that enables table editing.
<a name="line17"></a> *
<a name="line18"></a> * @see ../../demos/editor/tableeditor.html
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.editor.plugins.TableEditor&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line26"></a>goog.require(&#39;goog.editor.Plugin&#39;);
<a name="line27"></a>goog.require(&#39;goog.editor.Table&#39;);
<a name="line28"></a>goog.require(&#39;goog.editor.node&#39;);
<a name="line29"></a>goog.require(&#39;goog.editor.range&#39;);
<a name="line30"></a>goog.require(&#39;goog.object&#39;);
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * Plugin that adds support for table creation and editing commands.
<a name="line36"></a> * @constructor
<a name="line37"></a> * @extends {goog.editor.Plugin}
<a name="line38"></a> * @final
<a name="line39"></a> */
<a name="line40"></a>goog.editor.plugins.TableEditor = function() {
<a name="line41"></a>  goog.editor.plugins.TableEditor.base(this, &#39;constructor&#39;);
<a name="line42"></a>
<a name="line43"></a>  /**
<a name="line44"></a>   * The array of functions that decide whether a table element could be
<a name="line45"></a>   * editable by the user or not.
<a name="line46"></a>   * @type {Array.&lt;function(Element):boolean&gt;}
<a name="line47"></a>   * @private
<a name="line48"></a>   */
<a name="line49"></a>  this.isTableEditableFunctions_ = [];
<a name="line50"></a>
<a name="line51"></a>  /**
<a name="line52"></a>   * The pre-bound function that decides whether a table element could be
<a name="line53"></a>   * editable by the user or not overall.
<a name="line54"></a>   * @type {function(Node):boolean}
<a name="line55"></a>   * @private
<a name="line56"></a>   */
<a name="line57"></a>  this.isUserEditableTableBound_ = goog.bind(this.isUserEditableTable_, this);
<a name="line58"></a>};
<a name="line59"></a>goog.inherits(goog.editor.plugins.TableEditor, goog.editor.Plugin);
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>/** @override */
<a name="line63"></a>// TODO(user): remove this once there&#39;s a sensible default
<a name="line64"></a>// implementation in the base Plugin.
<a name="line65"></a>goog.editor.plugins.TableEditor.prototype.getTrogClassId = function() {
<a name="line66"></a>  return String(goog.getUid(this.constructor));
<a name="line67"></a>};
<a name="line68"></a>
<a name="line69"></a>
<a name="line70"></a>/**
<a name="line71"></a> * Commands supported by goog.editor.plugins.TableEditor.
<a name="line72"></a> * @enum {string}
<a name="line73"></a> */
<a name="line74"></a>goog.editor.plugins.TableEditor.COMMAND = {
<a name="line75"></a>  TABLE: &#39;+table&#39;,
<a name="line76"></a>  INSERT_ROW_AFTER: &#39;+insertRowAfter&#39;,
<a name="line77"></a>  INSERT_ROW_BEFORE: &#39;+insertRowBefore&#39;,
<a name="line78"></a>  INSERT_COLUMN_AFTER: &#39;+insertColumnAfter&#39;,
<a name="line79"></a>  INSERT_COLUMN_BEFORE: &#39;+insertColumnBefore&#39;,
<a name="line80"></a>  REMOVE_ROWS: &#39;+removeRows&#39;,
<a name="line81"></a>  REMOVE_COLUMNS: &#39;+removeColumns&#39;,
<a name="line82"></a>  SPLIT_CELL: &#39;+splitCell&#39;,
<a name="line83"></a>  MERGE_CELLS: &#39;+mergeCells&#39;,
<a name="line84"></a>  REMOVE_TABLE: &#39;+removeTable&#39;
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * Inverse map of execCommand strings to
<a name="line90"></a> * {@link goog.editor.plugins.TableEditor.COMMAND} constants. Used to
<a name="line91"></a> * determine whether a string corresponds to a command this plugin handles
<a name="line92"></a> * in O(1) time.
<a name="line93"></a> * @type {Object}
<a name="line94"></a> * @private
<a name="line95"></a> */
<a name="line96"></a>goog.editor.plugins.TableEditor.SUPPORTED_COMMANDS_ =
<a name="line97"></a>    goog.object.transpose(goog.editor.plugins.TableEditor.COMMAND);
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/**
<a name="line101"></a> * Whether the string corresponds to a command this plugin handles.
<a name="line102"></a> * @param {string} command Command string to check.
<a name="line103"></a> * @return {boolean} Whether the string corresponds to a command
<a name="line104"></a> *     this plugin handles.
<a name="line105"></a> * @override
<a name="line106"></a> */
<a name="line107"></a>goog.editor.plugins.TableEditor.prototype.isSupportedCommand =
<a name="line108"></a>    function(command) {
<a name="line109"></a>  return command in goog.editor.plugins.TableEditor.SUPPORTED_COMMANDS_;
<a name="line110"></a>};
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/** @override */
<a name="line114"></a>goog.editor.plugins.TableEditor.prototype.enable = function(fieldObject) {
<a name="line115"></a>  goog.editor.plugins.TableEditor.base(this, &#39;enable&#39;, fieldObject);
<a name="line116"></a>
<a name="line117"></a>  // enableObjectResizing is supported only for Gecko.
<a name="line118"></a>  // You can refer to http://qooxdoo.org/contrib/project/htmlarea/html_editing
<a name="line119"></a>  // for a compatibility chart.
<a name="line120"></a>  if (goog.userAgent.GECKO) {
<a name="line121"></a>    var doc = this.getFieldDomHelper().getDocument();
<a name="line122"></a>    doc.execCommand(&#39;enableObjectResizing&#39;, false, &#39;true&#39;);
<a name="line123"></a>  }
<a name="line124"></a>};
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * Returns the currently selected table.
<a name="line129"></a> * @return {Element?} The table in which the current selection is
<a name="line130"></a> *     contained, or null if there isn&#39;t such a table.
<a name="line131"></a> * @private
<a name="line132"></a> */
<a name="line133"></a>goog.editor.plugins.TableEditor.prototype.getCurrentTable_ = function() {
<a name="line134"></a>  var selectedElement = this.getFieldObject().getRange().getContainer();
<a name="line135"></a>  return this.getAncestorTable_(selectedElement);
<a name="line136"></a>};
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>/**
<a name="line140"></a> * Finds the first user-editable table element in the input node&#39;s ancestors.
<a name="line141"></a> * @param {Node?} node The node to start with.
<a name="line142"></a> * @return {Element?} The table element that is closest ancestor of the node.
<a name="line143"></a> * @private
<a name="line144"></a> */
<a name="line145"></a>goog.editor.plugins.TableEditor.prototype.getAncestorTable_ = function(node) {
<a name="line146"></a>  var ancestor = goog.dom.getAncestor(node, this.isUserEditableTableBound_,
<a name="line147"></a>      true);
<a name="line148"></a>  if (goog.editor.node.isEditable(ancestor)) {
<a name="line149"></a>    return /** @type {Element?} */(ancestor);
<a name="line150"></a>  } else {
<a name="line151"></a>    return null;
<a name="line152"></a>  }
<a name="line153"></a>};
<a name="line154"></a>
<a name="line155"></a>
<a name="line156"></a>/**
<a name="line157"></a> * Returns the current value of a given command. Currently this plugin
<a name="line158"></a> * only returns a value for goog.editor.plugins.TableEditor.COMMAND.TABLE.
<a name="line159"></a> * @override
<a name="line160"></a> */
<a name="line161"></a>goog.editor.plugins.TableEditor.prototype.queryCommandValue =
<a name="line162"></a>    function(command) {
<a name="line163"></a>  if (command == goog.editor.plugins.TableEditor.COMMAND.TABLE) {
<a name="line164"></a>    return !!this.getCurrentTable_();
<a name="line165"></a>  }
<a name="line166"></a>};
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/** @override */
<a name="line170"></a>goog.editor.plugins.TableEditor.prototype.execCommandInternal = function(
<a name="line171"></a>    command, opt_arg) {
<a name="line172"></a>  var result = null;
<a name="line173"></a>  // TD/TH in which to place the cursor, if the command destroys the current
<a name="line174"></a>  // cursor position.
<a name="line175"></a>  var cursorCell = null;
<a name="line176"></a>  var range = this.getFieldObject().getRange();
<a name="line177"></a>  if (command == goog.editor.plugins.TableEditor.COMMAND.TABLE) {
<a name="line178"></a>    // Don&#39;t create a table if the cursor isn&#39;t in an editable region.
<a name="line179"></a>    if (!goog.editor.range.isEditable(range)) {
<a name="line180"></a>      return null;
<a name="line181"></a>    }
<a name="line182"></a>    // Create the table.
<a name="line183"></a>    var tableProps = opt_arg || {width: 4, height: 2};
<a name="line184"></a>    var doc = this.getFieldDomHelper().getDocument();
<a name="line185"></a>    var table = goog.editor.Table.createDomTable(
<a name="line186"></a>        doc, tableProps.width, tableProps.height);
<a name="line187"></a>    range.replaceContentsWithNode(table);
<a name="line188"></a>    // In IE, replaceContentsWithNode uses pasteHTML, so we lose our reference
<a name="line189"></a>    // to the inserted table.
<a name="line190"></a>    // TODO(user): use the reference to the table element returned from
<a name="line191"></a>    // replaceContentsWithNode.
<a name="line192"></a>    if (!goog.userAgent.IE) {
<a name="line193"></a>      cursorCell = table.getElementsByTagName(&#39;td&#39;)[0];
<a name="line194"></a>    }
<a name="line195"></a>  } else {
<a name="line196"></a>    var cellSelection = new goog.editor.plugins.TableEditor.CellSelection_(
<a name="line197"></a>        range, goog.bind(this.getAncestorTable_, this));
<a name="line198"></a>    var table = cellSelection.getTable();
<a name="line199"></a>    if (!table) {
<a name="line200"></a>      return null;
<a name="line201"></a>    }
<a name="line202"></a>    switch (command) {
<a name="line203"></a>      case goog.editor.plugins.TableEditor.COMMAND.INSERT_ROW_BEFORE:
<a name="line204"></a>        table.insertRow(cellSelection.getFirstRowIndex());
<a name="line205"></a>        break;
<a name="line206"></a>      case goog.editor.plugins.TableEditor.COMMAND.INSERT_ROW_AFTER:
<a name="line207"></a>        table.insertRow(cellSelection.getLastRowIndex() + 1);
<a name="line208"></a>        break;
<a name="line209"></a>      case goog.editor.plugins.TableEditor.COMMAND.INSERT_COLUMN_BEFORE:
<a name="line210"></a>        table.insertColumn(cellSelection.getFirstColumnIndex());
<a name="line211"></a>        break;
<a name="line212"></a>      case goog.editor.plugins.TableEditor.COMMAND.INSERT_COLUMN_AFTER:
<a name="line213"></a>        table.insertColumn(cellSelection.getLastColumnIndex() + 1);
<a name="line214"></a>        break;
<a name="line215"></a>      case goog.editor.plugins.TableEditor.COMMAND.REMOVE_ROWS:
<a name="line216"></a>        var startRow = cellSelection.getFirstRowIndex();
<a name="line217"></a>        var endRow = cellSelection.getLastRowIndex();
<a name="line218"></a>        if (startRow == 0 &amp;&amp; endRow == (table.rows.length - 1)) {
<a name="line219"></a>          // Instead of deleting all rows, delete the entire table.
<a name="line220"></a>          return this.execCommandInternal(
<a name="line221"></a>              goog.editor.plugins.TableEditor.COMMAND.REMOVE_TABLE);
<a name="line222"></a>        }
<a name="line223"></a>        var startColumn = cellSelection.getFirstColumnIndex();
<a name="line224"></a>        var rowCount = (endRow - startRow) + 1;
<a name="line225"></a>        for (var i = 0; i &lt; rowCount; i++) {
<a name="line226"></a>          table.removeRow(startRow);
<a name="line227"></a>        }
<a name="line228"></a>        if (table.rows.length &gt; 0) {
<a name="line229"></a>          // Place cursor in the previous/first row.
<a name="line230"></a>          var closestRow = Math.min(startRow, table.rows.length - 1);
<a name="line231"></a>          cursorCell = table.rows[closestRow].columns[startColumn].element;
<a name="line232"></a>        }
<a name="line233"></a>        break;
<a name="line234"></a>      case goog.editor.plugins.TableEditor.COMMAND.REMOVE_COLUMNS:
<a name="line235"></a>        var startCol = cellSelection.getFirstColumnIndex();
<a name="line236"></a>        var endCol = cellSelection.getLastColumnIndex();
<a name="line237"></a>        if (startCol == 0 &amp;&amp; endCol == (table.rows[0].columns.length - 1)) {
<a name="line238"></a>          // Instead of deleting all columns, delete the entire table.
<a name="line239"></a>          return this.execCommandInternal(
<a name="line240"></a>              goog.editor.plugins.TableEditor.COMMAND.REMOVE_TABLE);
<a name="line241"></a>        }
<a name="line242"></a>        var startRow = cellSelection.getFirstRowIndex();
<a name="line243"></a>        var removeCount = (endCol - startCol) + 1;
<a name="line244"></a>        for (var i = 0; i &lt; removeCount; i++) {
<a name="line245"></a>          table.removeColumn(startCol);
<a name="line246"></a>        }
<a name="line247"></a>        var currentRow = table.rows[startRow];
<a name="line248"></a>        if (currentRow) {
<a name="line249"></a>          // Place cursor in the previous/first column.
<a name="line250"></a>          var closestCol = Math.min(startCol, currentRow.columns.length - 1);
<a name="line251"></a>          cursorCell = currentRow.columns[closestCol].element;
<a name="line252"></a>        }
<a name="line253"></a>        break;
<a name="line254"></a>      case goog.editor.plugins.TableEditor.COMMAND.MERGE_CELLS:
<a name="line255"></a>        if (cellSelection.isRectangle()) {
<a name="line256"></a>          table.mergeCells(cellSelection.getFirstRowIndex(),
<a name="line257"></a>                           cellSelection.getFirstColumnIndex(),
<a name="line258"></a>                           cellSelection.getLastRowIndex(),
<a name="line259"></a>                           cellSelection.getLastColumnIndex());
<a name="line260"></a>        }
<a name="line261"></a>        break;
<a name="line262"></a>      case goog.editor.plugins.TableEditor.COMMAND.SPLIT_CELL:
<a name="line263"></a>        if (cellSelection.containsSingleCell()) {
<a name="line264"></a>          table.splitCell(cellSelection.getFirstRowIndex(),
<a name="line265"></a>                          cellSelection.getFirstColumnIndex());
<a name="line266"></a>        }
<a name="line267"></a>        break;
<a name="line268"></a>      case goog.editor.plugins.TableEditor.COMMAND.REMOVE_TABLE:
<a name="line269"></a>        table.element.parentNode.removeChild(table.element);
<a name="line270"></a>        break;
<a name="line271"></a>      default:
<a name="line272"></a>    }
<a name="line273"></a>  }
<a name="line274"></a>  if (cursorCell) {
<a name="line275"></a>    range = goog.dom.Range.createFromNodeContents(cursorCell);
<a name="line276"></a>    range.collapse(false);
<a name="line277"></a>    range.select();
<a name="line278"></a>  }
<a name="line279"></a>  return result;
<a name="line280"></a>};
<a name="line281"></a>
<a name="line282"></a>
<a name="line283"></a>/**
<a name="line284"></a> * Checks whether the element is a table editable by the user.
<a name="line285"></a> * @param {Node} element The element in question.
<a name="line286"></a> * @return {boolean} Whether the element is a table editable by the user.
<a name="line287"></a> * @private
<a name="line288"></a> */
<a name="line289"></a>goog.editor.plugins.TableEditor.prototype.isUserEditableTable_ =
<a name="line290"></a>    function(element) {
<a name="line291"></a>  // Default implementation.
<a name="line292"></a>  if (element.tagName != goog.dom.TagName.TABLE) {
<a name="line293"></a>    return false;
<a name="line294"></a>  }
<a name="line295"></a>
<a name="line296"></a>  // Check for extra user-editable filters.
<a name="line297"></a>  return goog.array.every(this.isTableEditableFunctions_, function(func) {
<a name="line298"></a>    return func(/** @type {Element} */ (element));
<a name="line299"></a>  });
<a name="line300"></a>};
<a name="line301"></a>
<a name="line302"></a>
<a name="line303"></a>/**
<a name="line304"></a> * Adds a function to filter out non-user-editable tables.
<a name="line305"></a> * @param {function(Element):boolean} func A function to decide whether the
<a name="line306"></a> *   table element could be editable by the user or not.
<a name="line307"></a> */
<a name="line308"></a>goog.editor.plugins.TableEditor.prototype.addIsTableEditableFunction =
<a name="line309"></a>    function(func) {
<a name="line310"></a>  goog.array.insert(this.isTableEditableFunctions_, func);
<a name="line311"></a>};
<a name="line312"></a>
<a name="line313"></a>
<a name="line314"></a>
<a name="line315"></a>/**
<a name="line316"></a> * Class representing the selected cell objects within a single  table.
<a name="line317"></a> * @param {goog.dom.AbstractRange} range Selected range from which to calculate
<a name="line318"></a> *     selected cells.
<a name="line319"></a> * @param {function(Element):Element?} getParentTableFunction A function that
<a name="line320"></a> *     finds the user-editable table from a given element.
<a name="line321"></a> * @constructor
<a name="line322"></a> * @private
<a name="line323"></a> */
<a name="line324"></a>goog.editor.plugins.TableEditor.CellSelection_ =
<a name="line325"></a>    function(range, getParentTableFunction) {
<a name="line326"></a>  this.cells_ = [];
<a name="line327"></a>
<a name="line328"></a>  // Mozilla lets users select groups of cells, with each cell showing
<a name="line329"></a>  // up as a separate range in the selection. goog.dom.Range doesn&#39;t
<a name="line330"></a>  // currently support this.
<a name="line331"></a>  // TODO(user): support this case in range.js
<a name="line332"></a>  var selectionContainer = range.getContainerElement();
<a name="line333"></a>  var elementInSelection = function(node) {
<a name="line334"></a>    // TODO(user): revert to the more liberal containsNode(node, true),
<a name="line335"></a>    // which will match partially-selected cells. We&#39;re using
<a name="line336"></a>    // containsNode(node, false) at the moment because otherwise it&#39;s
<a name="line337"></a>    // broken in WebKit due to a closure range bug.
<a name="line338"></a>    return selectionContainer == node ||
<a name="line339"></a>        selectionContainer.parentNode == node ||
<a name="line340"></a>        range.containsNode(node, false);
<a name="line341"></a>  };
<a name="line342"></a>
<a name="line343"></a>  var parentTableElement = selectionContainer &amp;&amp;
<a name="line344"></a>      getParentTableFunction(selectionContainer);
<a name="line345"></a>  if (!parentTableElement) {
<a name="line346"></a>    return;
<a name="line347"></a>  }
<a name="line348"></a>
<a name="line349"></a>  var parentTable = new goog.editor.Table(parentTableElement);
<a name="line350"></a>  // It&#39;s probably not possible to select a table with no cells, but
<a name="line351"></a>  // do a sanity check anyway.
<a name="line352"></a>  if (!parentTable.rows.length || !parentTable.rows[0].columns.length) {
<a name="line353"></a>    return;
<a name="line354"></a>  }
<a name="line355"></a>  // Loop through cells to calculate dimensions for this CellSelection.
<a name="line356"></a>  for (var i = 0, row; row = parentTable.rows[i]; i++) {
<a name="line357"></a>    for (var j = 0, cell; cell = row.columns[j]; j++) {
<a name="line358"></a>      if (elementInSelection(cell.element)) {
<a name="line359"></a>        // Update dimensions based on cell.
<a name="line360"></a>        if (!this.cells_.length) {
<a name="line361"></a>          this.firstRowIndex_ = cell.startRow;
<a name="line362"></a>          this.lastRowIndex_ = cell.endRow;
<a name="line363"></a>          this.firstColIndex_ = cell.startCol;
<a name="line364"></a>          this.lastColIndex_ = cell.endCol;
<a name="line365"></a>        } else {
<a name="line366"></a>          this.firstRowIndex_ = Math.min(this.firstRowIndex_, cell.startRow);
<a name="line367"></a>          this.lastRowIndex_ = Math.max(this.lastRowIndex_, cell.endRow);
<a name="line368"></a>          this.firstColIndex_ = Math.min(this.firstColIndex_, cell.startCol);
<a name="line369"></a>          this.lastColIndex_ = Math.max(this.lastColIndex_, cell.endCol);
<a name="line370"></a>        }
<a name="line371"></a>        this.cells_.push(cell);
<a name="line372"></a>      }
<a name="line373"></a>    }
<a name="line374"></a>  }
<a name="line375"></a>  this.parentTable_ = parentTable;
<a name="line376"></a>};
<a name="line377"></a>
<a name="line378"></a>
<a name="line379"></a>/**
<a name="line380"></a> * Returns the EditableTable object of which this selection&#39;s cells are a
<a name="line381"></a> * subset.
<a name="line382"></a> * @return {!goog.editor.Table} the table.
<a name="line383"></a> */
<a name="line384"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getTable =
<a name="line385"></a>    function() {
<a name="line386"></a>  return this.parentTable_;
<a name="line387"></a>};
<a name="line388"></a>
<a name="line389"></a>
<a name="line390"></a>/**
<a name="line391"></a> * Returns the row index of the uppermost cell in this selection.
<a name="line392"></a> * @return {number} The row index.
<a name="line393"></a> */
<a name="line394"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getFirstRowIndex =
<a name="line395"></a>    function() {
<a name="line396"></a>  return this.firstRowIndex_;
<a name="line397"></a>};
<a name="line398"></a>
<a name="line399"></a>
<a name="line400"></a>/**
<a name="line401"></a> * Returns the row index of the lowermost cell in this selection.
<a name="line402"></a> * @return {number} The row index.
<a name="line403"></a> */
<a name="line404"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getLastRowIndex =
<a name="line405"></a>    function() {
<a name="line406"></a>  return this.lastRowIndex_;
<a name="line407"></a>};
<a name="line408"></a>
<a name="line409"></a>
<a name="line410"></a>/**
<a name="line411"></a> * Returns the column index of the farthest left cell in this selection.
<a name="line412"></a> * @return {number} The column index.
<a name="line413"></a> */
<a name="line414"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getFirstColumnIndex =
<a name="line415"></a>    function() {
<a name="line416"></a>  return this.firstColIndex_;
<a name="line417"></a>};
<a name="line418"></a>
<a name="line419"></a>
<a name="line420"></a>/**
<a name="line421"></a> * Returns the column index of the farthest right cell in this selection.
<a name="line422"></a> * @return {number} The column index.
<a name="line423"></a> */
<a name="line424"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getLastColumnIndex =
<a name="line425"></a>    function() {
<a name="line426"></a>  return this.lastColIndex_;
<a name="line427"></a>};
<a name="line428"></a>
<a name="line429"></a>
<a name="line430"></a>/**
<a name="line431"></a> * Returns the cells in this selection.
<a name="line432"></a> * @return {!Array.&lt;Element&gt;} Cells in this selection.
<a name="line433"></a> */
<a name="line434"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.getCells = function() {
<a name="line435"></a>  return this.cells_;
<a name="line436"></a>};
<a name="line437"></a>
<a name="line438"></a>
<a name="line439"></a>/**
<a name="line440"></a> * Returns a boolean value indicating whether or not the cells in this
<a name="line441"></a> * selection form a rectangle.
<a name="line442"></a> * @return {boolean} Whether the selection forms a rectangle.
<a name="line443"></a> */
<a name="line444"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.isRectangle =
<a name="line445"></a>    function() {
<a name="line446"></a>  // TODO(user): check for missing cells. Right now this returns
<a name="line447"></a>  // whether all cells in the selection are in the rectangle, but doesn&#39;t
<a name="line448"></a>  // verify that every expected cell is present.
<a name="line449"></a>  if (!this.cells_.length) {
<a name="line450"></a>    return false;
<a name="line451"></a>  }
<a name="line452"></a>  var firstCell = this.cells_[0];
<a name="line453"></a>  var lastCell = this.cells_[this.cells_.length - 1];
<a name="line454"></a>  return !(this.firstRowIndex_ &lt; firstCell.startRow ||
<a name="line455"></a>           this.lastRowIndex_ &gt; lastCell.endRow ||
<a name="line456"></a>           this.firstColIndex_ &lt; firstCell.startCol ||
<a name="line457"></a>           this.lastColIndex_ &gt; lastCell.endCol);
<a name="line458"></a>};
<a name="line459"></a>
<a name="line460"></a>
<a name="line461"></a>/**
<a name="line462"></a> * Returns a boolean value indicating whether or not there is exactly
<a name="line463"></a> * one cell in this selection. Note that this may not be the same as checking
<a name="line464"></a> * whether getCells().length == 1; if there is a single cell with
<a name="line465"></a> * rowSpan/colSpan set it will appear multiple times.
<a name="line466"></a> * @return {boolean} Whether there is exatly one cell in this selection.
<a name="line467"></a> */
<a name="line468"></a>goog.editor.plugins.TableEditor.CellSelection_.prototype.containsSingleCell =
<a name="line469"></a>    function() {
<a name="line470"></a>  var cellCount = this.cells_.length;
<a name="line471"></a>  return cellCount &gt; 0 &amp;&amp;
<a name="line472"></a>      (this.cells_[0] == this.cells_[cellCount - 1]);
<a name="line473"></a>};
</pre>


</body>
</html>
